from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from unittest import runner

# 打开浏览器
driver = webdriver.Chrome()
# 访问的网页
driver.get('http://192.168.1.25/crm')
driver.implicitly_wait(30)
# 最大化窗口
driver.maximize_window()

username = '杨应科'
password = '123456'

# 定位器
username_shuru_locator = (By.NAME,'name')
password_shuru_locator = (By.NAME,'password')
dl_dianji_locator = (By.NAME,'submit')
dianji_cp_locator = (By.CSS_SELECTOR,'body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul:nth-child(1) > li:nth-child(4) > a')
cpgj_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(2) > div.pull-right > div > button')
drcp_locator = (By.CSS_SELECTOR,'#import_excel')
qxdr_locator = (By.CSS_SELECTOR,'#dialog-import > form > table > tbody > tr:nth-child(4) > td:nth-child(2) > input:nth-child(2)')

# 执行
driver.find_element(*username_shuru_locator).send_keys(username)
driver.find_element(*password_shuru_locator).send_keys(password)
driver.find_element(*dl_dianji_locator).click()
driver.find_element(*dianji_cp_locator).click()
driver.find_element(*cpgj_locator).click()
driver.find_element(*drcp_locator).click()
sleep(1)
driver.find_element(*qxdr_locator).click()
sleep(2)
driver.quit()